package com.example.userdome.controller;

import com.example.userdome.pojo.Score;
import com.example.userdome.pojo.ServiceResponse;
import com.example.userdome.pojo.User;
import com.example.userdome.service.IScoreService;
import com.example.userdome.service.IUserService;
import com.example.userdome.service.ScoreService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/users")
public class StudentSystemController {
    @Resource
    private IUserService iUserService;
    @Resource
    private IScoreService iScoreService;

    @Resource
    private ScoreService scoreService;


    //通过id修改数据
    @PutMapping("/updateUserTableById/{id}")
    public Boolean updateUserTableById(@PathVariable Integer id, @RequestBody User user) {
        return iUserService.updateById(user);
    }

    @GetMapping("/selectByParam")
    public List<User> selectByParam(@RequestParam(required = false) Integer id,
                                    @RequestParam(required = false) String username,
                                    @RequestParam(required = false) String password){
        return iUserService.selectByAll(id, username, password);
    }

    //查询学号下的所有成绩
    @GetMapping("/getAllScore")
    public List<Score> getAllScore() {
        return iScoreService.list();
    }


    //通过id修改或者添加成绩数据（0<=score<=100）
    @PutMapping("/updateScoreTableById/{id}")
    public void updateScoreTableById(@PathVariable Integer id,
                                     @RequestParam int math,
                                     @RequestParam int chinese,
                                     @RequestParam int english) {
       scoreService.updateScoreById(id, math, chinese, english);
    }
}
